home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / yase.arc / GROUP1.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-12-13  |  6.6 KB  |  198 lines

  1. ******************************************************************
  2. * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
  3. * - Note: This is a real, live, actual, registered copyright,
  4. *   and should be treated as such. This source code is from
  5. *   the book "68000 Assembly Language", Krantz and Stanley,
  6. *   Addison-Wesley Publishing Company, Reading, MA, 1986.
  7. *   Permission granted by the authors for non-commercial use
  8. *   in programs released to the public domain, as long as this
  9. *   copyright notice remains attached and visible.
  10. *
  11. *****************************************************************
  12. * GROUP 1 (Quick) Commands
  13.  
  14.     xref    _getkey,ask,case,cnt_nl,default,dirty,eol,findpat
  15.     xref    prompt,repflag,reppat,seek,sol
  16.     xdef    group_1,refind,to_end,home
  17.  
  18. #edit.h
  19. #cursor.h
  20. *****************************************************************
  21. * GROUP_1 - group 1 (quick) commands
  22. group_1:
  23.     move.l    #q_cmd,a0    * load up prompt address
  24.     bsr    prompt        * output prompt
  25.     bsr    _getkey        * get switch key
  26.     and.w    #$001F,d0    * make u/l, l/c letters cntrl
  27.     move.l    #table1,a0    * load up case table address
  28.     bra    case        * returns to caller of group_2
  29. q_cmd:    dc.b    'Quick Command: A B C D F K R S',0
  30.     dc.w    0
  31.  
  32. *****************************************************************
  33. * TABLE_1 - switch table for group 1 commands
  34. table1:
  35.     dc.w    8
  36.     dc.w    $01        * ^A find/replace
  37.     dc.l    find_repl
  38.     dc.w    $02        * ^B find block start
  39.     dc.l    find_b_s
  40.     dc.w    $03        * ^C to end of file
  41.     dc.l    to_end
  42.     dc.w    $06        * ^F find
  43.     dc.l    find    
  44.     dc.w    $0B        * ^K find block end
  45.     dc.l    find_b_e
  46.     dc.w    $04        * ^D end of line
  47.     dc.l    eol
  48.     dc.w    $12        * ^R top of file
  49.     dc.l    home
  50.     dc.w    $13        * ^S start of line
  51.     dc.l    sol
  52.     dc.l    default
  53. *****************************************************************
  54. find:
  55.     move.l    #fwhat,a0    * prompt string address
  56.     move.l    #findpat,a1    * find pattern string address
  57.     bsr    ask        * see what human wants
  58.     clr.w    repflag        * zero "replace" flag
  59.     bsr    refind        * go find it
  60.     rts
  61. fwhat:    dc.b    'Find: ',0
  62.     dc.w    0
  63. *****************************************************************
  64. find_repl:
  65.     move.l    #fwhat,a0    * prompt string address
  66.     move.l    #findpat,a1    * find pattern string address
  67.     bsr    ask        * see what human wants
  68.     move.l    #rwhat,a0    * prompt string address
  69.     move.l    #reppat,a1    * replace pattern string address
  70.     bsr    ask        * get reply
  71.     move.w    #-1,repflag    * set "replace" flag
  72.     bsr    refind        * go find it
  73.     rts
  74. rwhat:    dc.b    'Replace: ',0
  75.     dc.w    0
  76. *****************************************************************
  77. refind:
  78.     move.l    e_buf(a5),d0    * calculate bytes past cursor
  79.     sub.l    e_gap(a5),d0    * D0 is bytes + 1
  80.     addq.l    #1,d0        * adjust byte count to actual
  81.     move.l    e_gap(a5),a0    * a0 will be search location
  82.     andi    #$FB,ccr    * reset zero flag
  83.     bra    sk0_ref        * do loop test before looping
  84. lp0_ref:
  85.     move.l    #findpat,a1    * a1 will be search pattern
  86.     addq.l    #1,a0        * bump start pointer
  87.     bsr    instr        * do instring compare
  88. sk0_ref:
  89.     dbeq    d0,lp0_ref    * loop if (d0) AND not zero flag
  90.     bne    sk1_ref        * jump if not found
  91.     move.l    e_gap(a5),a2    * setup to move cursor
  92.     move.l    b_gap(a5),d0    * calculate bytes to move
  93.     sub.l    a2,a0        * a0 holds bytes to move
  94.     add.l    a0,d0        * a1 is desired cursor location 
  95.     bsr    seek        * move cursor
  96.     tst.w    repflag        * see if we're replacing
  97.     beq    sk2_ref        * jump if no.
  98. * replace
  99.     bsr    dirty        * mark file as modified
  100.     move.l    #findpat,a1    * we'll use brute force
  101.     move.l    e_gap(a5),a0    * get end-of-gap
  102. lp1_ref:
  103.     tst.b    (a1)+        * look for end-of-find-pattern
  104.     beq    sk3_ref        * jump out at end of pattern
  105.     addq.l    #1,a0        * pop character out of file
  106.     bra    lp1_ref        * keep it up
  107. sk3_ref:
  108.     move.l    a0,e_gap(a5)    * delete "found" pattern
  109. * insert replacement string
  110. * we really ought to check for room here... 
  111.     move.l    #reppat,a1    * replacement string address
  112.     move.l    b_gap(a5),a0    * destination for string
  113.     move.l    a0,d0        * save cursor position for later
  114. lp2_ref:
  115.     tst.b    (a1)        * see if we have stuff to insert
  116.     beq    sk4_ref        * nope, all done.
  117.     move.b    (a1)+,(a0)+    * transfer a byte
  118.     bra    lp2_ref        * try for next byte
  119. sk4_ref:
  120.     move.l    a0,b_gap(a5)    * reset gap position
  121.     bsr    seek        * fix cursor position
  122.     bra    sk2_ref        * finished.
  123. sk1_ref:
  124.     move.w    #12,ed_err(a5)    * string-not-found error
  125. sk2_ref:
  126.     bsr    cnt_nl        * adjust line counter
  127.     rts
  128. *****************************************************************
  129. * INSTR - tests if a string in contained in the buffer.
  130. instr:
  131.     clr.l    d1        * d1 is compare count
  132. lp0_str:
  133.     tst.b    (a1)        * at end of pattern string?
  134.     beq    sk0_str        * jump if yes (we found it)
  135.     addq.l    #1,d1        * increment compare count
  136.     cmp.b    (a1)+,(a0)+    * check a byte - equal?
  137.     beq    lp0_str        * jump if no - no match
  138. sk0_str:
  139.     sub.l    d1,a0        * reset compare pointer
  140.     sub.l    d1,a1        * reset source pointer
  141.     rts
  142. *****************************************************************
  143. * HOME - moves cursor to top of file
  144. home:
  145.     move.l    b_gap(a5),d0    * get number of bytes to xfer
  146.     sub.l    b_buf(a5),d0    * d0 is number of bytes 
  147.     move.l    b_gap(a5),a0    * a0 is source address
  148.     move.l    e_gap(a5),a1    * a1 is destination address
  149.     bra    sk0_hm        * loop test before 1st transfer
  150. lp0_hm:
  151.     move.b    -(a0),-(a1)    * transfer across cursor gap
  152. sk0_hm:
  153.     dbra    d0,lp0_hm    * loop for all chars 
  154.     move.l    a0,b_gap(a5)    * save ending positions
  155.     move.l    a1,e_gap(a5)
  156.     clr.w    log_lin(a5)    * reset current line counter
  157.     rts    
  158. *****************************************************************
  159. * FIND_B_S - move the cursor to the beginning of the block
  160. find_b_s:
  161.     move.l    blk_st(a5),d0    * load marker
  162.     beq    sk0_fbs        * if zero, there's an error
  163.     bsr    seek        * go find the spot
  164.     bsr    cnt_nl        * reset line count
  165.     rts
  166. sk0_fbs:
  167.     move.w    #4,ed_err(a5)    * mark edit error #4 (block mark)
  168.     rts
  169. *****************************************************************
  170. * FIND_B_E - move the cursor to the end of the block
  171. find_b_e:
  172.     move.l    blk_end(a5),d0    * load marker
  173.     beq    sk0_fbe        * if zero, block's not marked.
  174.     bsr    seek        * go to the spot
  175.     bsr    cnt_nl        * reset line count
  176.     rts
  177. sk0_fbe:
  178.     move.w    #4,ed_err(a5)    * mark edit error #4 (block mark)
  179.     rts
  180. *****************************************************************
  181. * TO_END - moves cursor to end of file
  182. to_end:
  183.     move.l    e_buf(a5),d0    * get number of bytes to xfer
  184.     sub.l    e_gap(a5),d0    * d0 is number of bytes + 1
  185.     move.l    e_gap(a5),a0    * a0 is source address
  186.     move.l    b_gap(a5),a1    * a1 is destination address
  187.     addq.l    #1,d0        * adjust index for cursor update
  188.     bra    sk0_te        * loop test before 1st transfer
  189. lp0_te:
  190.     move.b    (a0)+,(a1)+    * transfer across cursor gap
  191. sk0_te:
  192.     dbra    d0,lp0_te    * loop for all chars 
  193.     move.l    a0,e_gap(a5)    * save ending positions
  194.     move.l    a1,b_gap(a5)
  195.     bsr    cnt_nl        * count lines to cursor
  196.     rts
  197.